package gui;

import javax.swing.table.*;

import java.util.ArrayList;

import model.*;
import control.*;

public class ProductTableList extends DefaultTableModel
{
	private ArrayList<Product> p = new ArrayList<Product>();
	
	public ProductTableList()
	{
		
	}
	
	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
	
	public void setP(ArrayList<Product> _p)
	{
		p = _p;
		fireTableDataChanged();
	}
	
	public ArrayList<Product> getP()
	{
		return p;
	}
	
	@Override
    public int getColumnCount()
	{
        return 9;
	}
	
	@Override
	public int getRowCount()
	{
		if(p == null)
		{
			return 0;
		}
		else
		{
			return p.size();
		}
	}
	
	@Override
    public String getColumnName(int column)
	{
        String columnName = "";
        switch (column)
        {
            case 0:
                columnName = "ID";
                break;
            case 1:
                columnName = "Name";
                break;
            case 2:
                columnName = "Purchase Price";
                break;
            case 3:
                columnName = "Sales Price";
                break;
            case 4:
                columnName = "Rent Price";
                break;
            case 5:
            	columnName = "Country";
            	break;
            case 6:
            	columnName = "Min Stock";
            	break;
            case 7:
            	columnName = "Supplier ID";
            	break;
            case 8:
            	columnName = "Product Type";
            	break;
        }
        return columnName;
    }
	
	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch (column)
		{
		case 0:
			value = p.get(row).getId();
			break;
		case 1:
			value = p.get(row).getName();
			break;
		case 2:
			value = p.get(row).getPurchasePrice();
			break;
		case 3:
			value = p.get(row).getSalesPrice();
			break;
		case 4:
			value = p.get(row).getRentPrice();
			break;
		case 5:
			value = p.get(row).getCountry();
			break;
		case 6:
			value = p.get(row).getMinStock();
			break;
		case 7:
			value = p.get(row).getSupplierID();
			break;
		case 8:
			value = p.get(row).getpType();
		}
		return value;
	}
}
